﻿using System;
using System.Web.UI;
using Wei8808Cms.BLL;
using Wei8808Cms.Model;
using Wei8808Cms.WebSite.UI;

namespace Wei8808Cms.WebSite.admin.Product
{
    public partial class AddProductInfoForm : BasicPage
    {
        private readonly ProductBLL _bll = new ProductBLL();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                chkLoginLevel("addProduct");
                int orderId = _bll.GetMaxOrderId();
                txtOrderId.Text = (orderId + 1).ToString();
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            var model = new ProductInfo();
            model.ProductName = txtProductName.Text.Trim();
            model.ProductTitle = txtProductTitle.Text.Trim();
            model.ProductContent = FCKeditor.Value;
            model.ProductIcon = txtProductIcon.Text.Trim();
            model.ProductImg = txtProductImg.Text.Trim();
            model.OrderId = int.Parse(txtOrderId.Text.Trim());
            model.Status = 0;
            if (cblItem.Items[0].Selected)
            {
                model.Status = 1;
            }
            model.CreateUser = "李波";
            model.CreateTime = DateTime.Now;
            if (_bll.Add(model))
            {
                JscriptPrint("保存成功！", "ProductMasterForm.aspx", "Success");
            }
            else
            {
                JscriptPrint("保存失败！", "", "Error");
            }
        }
    }
}